using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

using Pampa.Grid.Core.Filters;
using Pampa.CRUD.Configuration;
using Pampa.CRUD.UI.CustomControls;

using Pampa.Grid.Exceptions;

namespace Pampa.Grid.Core
{
    public class MainFilterDefinition
    {
        private EditItem item;
        private Type valueType;
        private MainFilterGroupDefinition parent;

        public MainFilterDefinition()
        {
        }
        
        public EditItem Item
        {
            get { return item;}
            set { item = value; }
        }

        public Type ValueType
        {
            get { return valueType; }
            set { valueType = value; }
        }

        public MainFilterGroupDefinition Parent
        {
            get { return parent; }
            set { parent = value; }
        }

        public static MainFilterDefinition LoadFromXml(XmlNode node)
        {
            MainFilterDefinition mainFilterDefinition = new MainFilterDefinition();

            mainFilterDefinition.Item = EditItem.LoadFromXml(node);
            mainFilterDefinition.Item.Enabled = true;

            if (node.Attributes["ValueType"] != null)
            {
                mainFilterDefinition.ValueType = Type.GetType(node.Attributes["ValueType"].Value);
            }

            if (mainFilterDefinition.ValueType == null)
            {
                mainFilterDefinition.ValueType = mainFilterDefinition.Item.ValueTypeDefault;
            }

            return mainFilterDefinition;
        }
    }
}
